﻿using MiniFox.Resources;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.Applications.Models
{
    /// <summary>
    /// 
    /// </summary>
    [JsonObject]
    public class SystemApp
    {
        /// <summary>
        /// 
        /// </summary>
        [Key, JsonProperty("appId")]
        public string AppID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("appName")]
        public string AppName { get; set; }
        /// <summary>
        /// 主机名/域名/ip
        /// </summary>
        [JsonIgnore]
        public string Host { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore]
        public string Path { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore]
        public string Port { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore]
        public bool RequireSSL { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("icon")]
        public string Icon { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("fullHost")]
        public string FullHost
        {
            get
            {
                if (!string.IsNullOrEmpty(this.Host))
                {
                    string host = this.Host.Replace("/", "");
                    string protocal = this.RequireSSL ? "https:" : "http:";
                    string port = (string.IsNullOrEmpty(this.Port) || this.Port.Trim() == "80") ? string.Empty : (":" + Port);
                    return (protocal + "//" + host + port).ToLower();

                }
                else
                {
                    return string.Empty;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("fullPath")]
        public string FullPath
        {
            get
            {
                if (string.IsNullOrEmpty(this.Path) || this.Path.Trim() == "/" || this.Path.Trim() == "~/")
                    return FullHost;
                string appPath = this.Path;
                if (!appPath.StartsWith("/"))
                    appPath = "/" + appPath;
                appPath = appPath.TrimEnd('/');
                return FullHost + appPath.ToLower();
            }
        }
    }
}
